package chatGUI;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/* 
 * @author Vansh and deepali
 */

public class FileNotifWindow extends JFrame {

//JPanel
    private JPanel pnlButton = new JPanel();
//Buttons
    private JButton acceptFileButton = new JButton("Yes");
    private JButton refuseFileButton = new JButton("No");
    private String username;
    private String filename;
    private ChatGui cg;

    public FileNotifWindow(final String username, final String filename, final ChatGui cg) {
        this.cg = cg;
        this.username = username;
        this.filename = filename;
        acceptFileButton.setBounds(60, 400, 220, 30);
        JTextArea tf = new JTextArea("            Would You Like To Accept The File : " + filename + "                 ");

        pnlButton.setBounds(800, 800, 200, 100);

        pnlButton.setLocation(0, 0);
        //Adding to JFrame
        pnlButton.add(tf);

        pnlButton.add(acceptFileButton);

        pnlButton.add(refuseFileButton);
        add(pnlButton);

        /**
         * If user accepts the fileproposal, the boolean 'accepted' in
         * GUIAnswerfile is set true.
         */
        acceptFileButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                //Execute when button is pressed
                cg.GUIAnswerFile(username, filename, true);
                setVisible(false);
                cg.buttonpressed();
            }
        });

        /**
         * If user refuses the fileproposal, the boolean 'accepted' in
         * GUIAnswerfile is set false.
         */
        refuseFileButton.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                cg.GUIAnswerFile(username, filename, false);
                setVisible(false);
                cg.buttonpressed();

            }
        });

        // JFrame properties
        setSize(400, 400);
        setBackground(Color.BLACK);
        setTitle("File Notification");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);

    }
}
